package com.fantastic.common.utils;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.exception.sql.SelectException;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
 * @author: rxx
 * @since: 2024/5/29 15:16
 * @description: 文件相关的操作进行封装
 */
public class FilesUtils {
    /**
     * 删除文件
     *
     * @param ap 文件的绝对路径
     * @return
     */
    public static void delete(Path ap) {
        try {
            Files.delete(ap);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 将路径字符串数组里的反斜杠替换成正斜杠
     * 正斜杠 ///
     *
     * @param relativePath
     * @return
     */
    public static String[] arraySlashParse(String[] relativePath) {
        if (relativePath.length != 0) {
            for (int i = 0; i < relativePath.length; i++) {
                relativePath[i] = relativePath[i].replace("\\", "/");
            }
        }
        return relativePath;
    }

    /**
     * 将路径字符串数组里的反斜杠替换成正斜杠
     * 正斜杠 ///
     *
     * @param relativePath
     * @return
     */
    public static String getSlashParse(String relativePath) {
        if (relativePath != null && relativePath != "") {
            return relativePath.replace("\\", "/");
        }
        return null;
    }

    /**
     * 将路径字符串数组里的正斜杠替换成反斜杠
     * 反斜杠 \\\
     *
     * @param relativePath
     * @return
     */
    public static String[] arrayBackslashParse(String[] relativePath) {
        if (relativePath.length != 0) {
            for (int i = 0; i < relativePath.length; i++) {
                relativePath[i] = relativePath[i].replace("/", "\\");
            }
        }
        return relativePath;
    }

    /**
     * 将路径里的正斜杠替换成反斜杠
     * 反斜杠 \\\
     *
     * @param relativePath
     * @return
     */
    public static String getBackslashParse(String relativePath) {
        if (relativePath != null && relativePath != "") {
            return relativePath.replace("/", "\\");
        }
        return null;
    }

}
